package util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import model.Blog;

//单例
public class JSONUtil {
    private static ObjectMapper objectMapper = null;
    //采用饿汉模式
    static {
        objectMapper = new ObjectMapper();
    }

    //alt + insert:生成构造方法或 getter/setter 方法
    //ctrl + alt + t: 生成try-catch代码块
    public static ObjectMapper getObjectMapper() {
        return objectMapper;
    }

    public static String toJson(Object o) throws JsonProcessingException {
        return objectMapper.writeValueAsString(o);
    }

}
